package com.briup.bookstore.web.controller;

import com.briup.bookstore.common.response.Result;
import com.briup.bookstore.common.security.SecurityContext;
import com.briup.bookstore.domain.bean.User;
import com.briup.bookstore.domain.dto.UserLoginDTO;
import com.briup.bookstore.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/user")
@RequiredArgsConstructor
public class AuthController {

    private final UserService userService;

    @PostMapping("/login")
    public Result<Map<String, Object>> login(
            @RequestBody UserLoginDTO userLoginDTO) {
        Map<String, Object> map = userService.login(userLoginDTO);
        return Result.success(map)
                .apply("登录成功");
    }

    @GetMapping("/getUserInfo")
    public Result<User> getUserInfo() {
        return Result.success(SecurityContext.currentUser())
                .apply("获取成功");
    }
}
